package com.zhentao.product.controller;

import com.zhentao.login.utils.Result;
import com.zhentao.nlz.project.dto.DictionaryDto;
import com.zhentao.nlz.project.product.TDictionary;
import com.zhentao.product.service.TDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("dictionary")
public class TDictionaryController {
    @Autowired
    private TDictionaryService tDictionaryService;


    @GetMapping("list")
    public Result list(DictionaryDto dto){
        return tDictionaryService.PagetDictionary(dto);
    }

    @PostMapping("save")
    public Result save(TDictionary dictionary){
        boolean save = tDictionaryService.save(dictionary);
        if(save){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }

    @PutMapping("update")
    public Result update(TDictionary dictionary){
        boolean update = tDictionaryService.updateById(dictionary);
        if(update){
            return Result.success("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }

    @DeleteMapping("delete")
    public Result delete(Integer id){
        boolean delete = tDictionaryService.removeById(id);
        if(delete){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
}
